package com.ruoyi.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.Advice;
import com.ruoyi.business.MyPage;
import com.ruoyi.business.PageConfig;
import com.ruoyi.business.mapper.AdviceMapper;
import com.ruoyi.business.qo.AdviceQO;
import com.ruoyi.common.common.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @title: UserService
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/2/8 12:55
 * @firstReview:
 * @lastReview:
 * @desc: 用户相关
 */
@Slf4j
@Component
public class AdviceService  extends ServiceImpl<AdviceMapper, Advice> {

    @Autowired
    private AdviceMapper adviceMapper;



    public ResultBody<IPage<Advice>> queryByPage(AdviceQO adviceQO) {
        MyPage myPage = PageConfig.getPage() ;
        Page<Advice> page = new Page<>(myPage.getPageNum(),myPage.getPageSize()) ;
        IPage<Advice> iPage = adviceMapper.queryPage(page,adviceQO) ;
        List<Advice> advices = iPage.getRecords() ;
        if(CollectionUtils.isEmpty(advices)){
            return ResultBody.success(iPage) ;
        }

        iPage = iPage.setRecords(advices) ;

        return ResultBody.success(iPage) ;
    }

    public Integer deal(Integer status,Integer id) {
        Advice advice = new Advice() ;
        advice.setStatus(status);
        advice.setId(id);

        return adviceMapper.updateByPrimaryKeySelective(advice) ;
    }


}
